package validators;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@ManagedBean(name = "validateBoolean")
@RequestScoped
public class ValidateBoolean implements Validator{
	

	public ValidateBoolean() {
		// TODO Auto-generated constructor stub
	}

	@Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

            Boolean visibility = (Boolean) value;

            if (visibility != true && visibility != false) {
                    throw new ValidatorException(generateMessage("may not be empty!", context));
            }
    }

    private FacesMessage generateMessage(String messageText, FacesContext context) {
            FacesMessage message = new FacesMessage();
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            message.setSummary(messageText);
            context.addMessage("userForm:sigla", message);
            return message;
    }

}
